package com.example.lx6_4.xq

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.base.entity.OrderEntityItem
import com.example.base.mvvm.BaseActivity
import com.example.lx6_4.R
import com.example.lx6_4.databinding.ActivityXqOrderBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/XqOrderActivity")
class XqOrderActivity : BaseActivity<ActivityXqOrderBinding, XqViewModel>() {

    @Autowired
    @JvmField
    var orderId = 0
    lateinit var ordersEntityItem : OrderEntityItem
    override fun initView() {
        ARouter.getInstance().inject(this)

        vm.getXq(orderId)

        binding.btn1.setOnClickListener {
            if(binding.tvProcessingStatus.text.toString() == "待处理"){
                ordersEntityItem.processingStatus = "处理中"
                vm.getUpData(orderId,ordersEntityItem)
            }
        }

        binding.btn2.setOnClickListener {
            if(binding.tvProcessingStatus.text.toString() == "处理中"){
                ordersEntityItem.processingStatus = "已完成"
                vm.getUpData(orderId,ordersEntityItem)
            }
        }
    }

    override fun initData() {
        vm.xqData.observe(this){
            ordersEntityItem = it
            binding.tvProcessingStatus.text = it.processingStatus
            binding.tvOrderNumber.text = "工单号："+ it.orderNumber
            binding.tvRepairTime.text = "报修时间："+ it.repairTime
            binding.tvRepairName.text = "联系人："+ it.repairName
            binding.tvRepairLocation.text = "位置："+ it.repairLocation
            binding.tvFaultDescription.text = "故障描述："+ it.faultDescription

            when(it.processingStatus){
                "待处理"->{
                    binding.vw1.setBackgroundResource(R.color.hui2)
                    binding.vw2.setBackgroundResource(R.color.hui2)
                    binding.iv2.setImageResource(R.drawable.ic_circle_fasle)
                    binding.iv3.setImageResource(R.drawable.ic_circle_fasle)
                }
                "处理中"->{
                    binding.vw1.setBackgroundResource(R.color.green)
                    binding.vw2.setBackgroundResource(R.color.hui2)
                    binding.iv2.setImageResource(R.drawable.ic_circle_true)
                    binding.iv3.setImageResource(R.drawable.ic_circle_fasle)
                }
                "已完成"->{
                    binding.llWan.isVisible = false
                    binding.vw1.setBackgroundResource(R.color.green)
                    binding.vw2.setBackgroundResource(R.color.green)
                    binding.iv2.setImageResource(R.drawable.ic_circle_true)
                    binding.iv3.setImageResource(R.drawable.ic_circle_true)
                }
            }
        }

        vm.upData.observe(this){
            vm.getUpRoom(it)
        }

        vm.upRoom.observe(this){
            ToastUtils.showLong("修改成功")
            vm.getXq(orderId)
        }

    }

    override fun onResume() {
        super.onResume()
        vm.getXq(orderId)
    }

}